import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 动态路由表 => 动态路由(需要权限才可以访问的) 我们这里准备一个数组存放

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/form',
    component: () => import('@/views/form/index'),
    hidden: false,
    meta: { title: '前台首页', icon: 'dashboard' }
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/employees',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'employees',
        component: () => import('@/views/employees'),
        meta: { title: '员工', icon: 'people' }
      }

    ]
  },

  {
    path: '/approvals',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'approvals',
        component: () => import('@/views/approvals'),
        meta: { title: '审批', icon: 'tree-table' }
      }
    ]
  },
  {
    path: '/attendances',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'attendances',
        component: () => import('@/views/attendances'),
        meta: { title: '考勤', icon: 'skill' }
      }
    ]
  },
  {
    path: '/departments',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'departments',
        component: () => import('@/views/departments'),
        meta: { title: '组织架构', icon: 'tree' }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'settings',
        component: () => import('@/views/setting'),
        meta: { title: '公司设置', icon: 'setting' }
      }
    ]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 本页写的静态路哟 谁都可以访问
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router

// 默认语法:
// 默认导出 export defaut
// 一个文件中只能有一个默认导出 [export default router]￥如果使用了默认导出 就必须使用默认导入
// import router from "@/router" [import后面的对象名可以随意取]

// 按需导出语法:
// 按需导出 export const constantRoutes =[]
// 要导入按需导出的成员 就必须使用按需导入
// 按需导出 可以导出多个成员
// 按需导入语法:import  {login } from "@/api/user"
// 按需导入起别名{} import  login as loginUser } from "@/api/user"
// 批量导入 import * as all from "@/api/user" all.login()
